﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Data;

namespace RenChangYou.Common
{
    public class Common
    {

        /// <summary>
        /// JS弹窗信息
        /// </summary>
        /// <param name="strMessage">Display Message</param>
        public static void AlertMessage(string strMessage)
        {
            string strJS = "<script language=javascript>alert('{0}');</script>";
            HttpContext.Current.Response.Write(string.Format(strJS, strMessage));

        }

        /// <summary>
        /// 弹出窗口并刷新页面
        /// </summary>
        /// <param name="strMessage"></param>
        /// <param name="strURL"></param>
        public static void AlertMessageAndRedirect(string strMessage, string strURL)
        {
            string strJS = "<script language=javascript>alert('{0}');location.href='{1}'</script>";
            HttpContext.Current.Response.Write(string.Format(strJS, strMessage, strURL));
        }



        /// <summary>
        /// MD5加密
        /// </summary>
        /// <param name="strValue">加密字符串</param>
        /// <returns>string</returns>
        public static string MD5Encrypt(string strValue)
        {
            return FormsAuthentication.HashPasswordForStoringInConfigFile(strValue, "MD5").ToString();
        }

        /// <summary>
        /// JS提示并在主窗口跳转
        /// </summary>
        /// <param name="strMessage">Message</param>
        /// <param name="strURL">URL</param>
        public static void ParentRedirect(string strURL)
        {
            string strJS = "<script language=javascript>window.parent.location='{0}'</script>";
            HttpContext.Current.Response.Write(string.Format(strJS, strURL));

        }
        /// <summary>
        /// 判断DataTable是否为空
        /// </summary>
        /// <param name="dt">DataTable</param>
        /// <returns>空:true</returns>
        public static bool DtIsNullOrEmpty(DataTable dt)
        {
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    return false;
                }
            }
            return true;
        }

    }
}
